<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Prettus\Repository\Contracts\Transformable;
use Prettus\Repository\Traits\TransformableTrait;

/**
 * Class DormMeter.
 *
 * @package namespace App\Models;
 */
class DormMeter extends BaseModel implements Transformable
{
    use TransformableTrait;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['dorm_id', 'meter_type_id', 'nfc_id', 'last_reading', 'last_reading_date', 'unit', 'active', 'install_date', 'expire_date', 'reset_limit'];
    public function dorm()
    {
        return $this->belongsTo(Dorm::class);
    }

    public function meter_type()
    {
        return $this->belongsTo(MeterType::class);
    }
    protected static function boot()
    {
        parent::boot();

        static::creating(function ($model) {
            if (auth()->check()) {
                $model->company_id = auth()->user()->company_id ?? null;
            }
        });
    }
}
